import request from '@/utils/request'

// 查询商品列表
export function listGoods(query) {
  return request({
    url: '/goods/list',
    method: 'get',
    params: query
  })
}

// 查询商品详细
export function getGoods(goodsId) {
  return request({
    url: '/goods/' + goodsId,
    method: 'get'
  })
}

// 新增商品
export function addGoods(data) {
  return request({
    url: '/goods',
    method: 'post',
    data: data
  })
}

// 修改商品
export function updateGoods(data) {
  return request({
    url: '/goods',
    method: 'put',
    data: data
  })
}

// 删除商品
export function delGoods(goodsId) {
  return request({
    url: '/goods/' + goodsId,
    method: 'delete'
  })
}

// 商品状态修改
export function changeGoodsStatus(goodsId, status) {
  const data = {
    goodsId,
    status
  }
  return request({
    url: '/goods/changeStatus',
    method: 'put',
    data: data
  })
}

// 获取商品分类树结构
export function getGoodsCategoryTree() {
  return request({
    url: '/goods/category/tree',
    method: 'get'
  })
}

// 根据父级ID获取商品分类
export function getGoodsCategoryByParent(parentId) {
  return request({
    url: '/goods/category/list',
    method: 'get',
    params: { parentId: parentId }
  })
}

// 获取虚拟商品分类
export function getVirtualCategory() {
  return request({
    url: '/goods/category/virtual',
    method: 'get'
  })
}

// 获取实物商品分类
export function getPhysicalCategory() {
  return request({
    url: '/goods/category/physical',
    method: 'get'
  })
}

// 获取店铺内部分类树结构
export function getShopCategoryTree() {
  return request({
    url: '/goods/shop/category/tree',
    method: 'get'
  })
}

// 根据父级ID获取店铺内部分类
export function getShopCategoryByParent(parentId) {
  return request({
    url: '/goods/shop/category/list',
    method: 'get',
    params: { parentId: parentId }
  })
}

// 获取当前登录商家信息
export function getCurrentMerchant() {
  return request({
    url: '/merchant/current',
    method: 'get'
  })
}

// 商品图片上传
export function uploadGoodsImage(data) {
  return request({
    url: '/goods/upload/image',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: data
  })
}

// 商品批量删除
export function delGoodsBatch(goodsIds) {
  return request({
    url: '/goods/batch/' + goodsIds,
    method: 'delete'
  })
}

// 商品导出
export function exportGoods(query) {
  return request({
    url: '/goods/export',
    method: 'get',
    params: query
  })
} 